<!DOCTYPE html>
<html lang="zh-CN" data-theme="light">

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1" />
  <meta name="generator" content="VuePress 2.0.0-beta.51" />
  <meta name="theme" content="VuePress Theme Hope" />
  <meta property="og:url" content="https://pro.autojs.org/docs/zh/v8/files.html">
  <meta property="og:site_name" content="Auto.js Pro文档">
  <meta property="og:title" content="files - 文件系统">
  <meta property="og:type" content="article">
  <meta property="og:updated_time" content="2022-10-22T07:36:15.000Z">
  <meta property="og:locale" content="zh-CN">
  <meta property="og:locale:alternate" content="en-US">
  <meta property="article:modified_time" content="2022-10-22T07:36:15.000Z">
  <link rel="alternate" hreflang="en-us" href="https://pro.autojs.org/docs/en/zh/v8/files.html">
  <link rel="icon" href="https://pro.autojs.org/docs/favicon.ico">
  <link rel="manifest" href="https://pro.autojs.org/docs/manifest.webmanifest" crossorigin="use-credentials">
  <meta name="theme-color" content="#46bd87">
  <meta name="viewport"
    content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
  <title>files - 文件系统 | Auto.js Pro文档</title>
  <meta name="description" content="支持Node.js的自动化工作流JavaScript IDE">
  <style>
    :root {
      --bg-color: #fff;
    }

    html[data-theme="dark"] {
      --bg-color: #1d2025;
    }

    html,
    body {
      background-color: var(--bg-color);
    }
  </style>
  <script>
    const userMode = localStorage.getItem("vuepress-theme-hope-scheme");
    const systemDarkMode =
      window.matchMedia &&
      window.matchMedia("(prefers-color-scheme: dark)").matches;

    if (userMode === "dark" || (userMode !== "light" && systemDarkMode)) {
      document.querySelector("html").setAttribute("data-theme", "dark");
    }
  </script>
  <link rel="stylesheet" href="../../assets/style.ae9cb182.css">
  <link rel="modulepreload" href="../../assets/app.6aa2b576.js">
  <link rel="modulepreload" href="../../assets/files.html.ae1884a1.js">
  <link rel="modulepreload" href="../../assets/_plugin-vue_export-helper.cdc0426e.js">
  <link rel="modulepreload" href="../../assets/files.html.cf2edeb4.js">
</head>

<body>


  <!-- Copyright � 2008. Spidersoft Ltd -->
  <style>
    A.applink:hover {
      border: 2px dotted #DCE6F4;
      padding: 2px;
      background-color: #ffff00;
      color: green;
      text-decoration: none
    }

    A.applink {
      border: 2px dotted #DCE6F4;
      padding: 2px;
      color: #2F5BFF;
      background: transparent;
      text-decoration: none
    }

    A.info {
      color: #2F5BFF;
      background: transparent;
      text-decoration: none
    }

    A.info:hover {
      color: green;
      background: transparent;
      text-decoration: underline
    }
  </style>


  <div id="app"><!--[--><!--[--><!--[--><span tabindex="-1"></span><a href="#main-content"
      class="skip-link sr-only">Skip to content</a><!--]-->
    <div class="theme-container has-toc"><!--[--><!--[-->
      <header class="navbar">
        <div class="navbar-left"><button class="toggle-sidebar-button" title="Toggle Sidebar"><span
              class="icon"></span></button><!----><a href="../../docs.html" class="brand"><img class="logo"
              src="../../logo.png" alt="Auto.js Pro文档"><!----><span class="site-name hide-in-pad">Auto.js
              Pro文档</span></a><!----></div>
        <div class="navbar-center"><!---->
          <nav class="nav-links">
            <div class="nav-item hide-in-mobile"><a href="../../docs.html" class="nav-link"
                aria-label="Auto.js Pro"><span class="icon iconfont icon-home"></span>Auto.js Pro<!----></a></div>
            <div class="nav-item hide-in-mobile"><a href="../guide/guide.html" class="nav-link" aria-label="指南"><span
                  class="icon iconfont icon-creative"></span>指南<!----></a></div>
            <div class="nav-item hide-in-mobile"><a href="v8.html" class="nav-link active" aria-label="第一代API文档"><span
                  class="icon iconfont icon-note"></span>第一代API文档<!----></a></div>
            <div class="nav-item hide-in-mobile"><a href="../v9/v9.html" class="nav-link" aria-label="第二代API文档"><span
                  class="icon iconfont icon-note"></span>第二代API文档<!----></a></div>
            <div class="nav-item hide-in-mobile">
              <div class="dropdown-wrapper"><button class="dropdown-title" type="button" aria-label="官网与相关链接"><span
                    class="title"><span class="icon iconfont icon-discover"></span>官网与相关链接</span><span
                    class="arrow"></span>
                  <ul class="nav-dropdown">
                    <li class="dropdown-item"><a href="../../../pro.autojs.html" rel="noopener noreferrer"
                        target="_blank" aria-label="官网与软件下载" class="nav-link"><!---->官网与软件下载<span><svg
                            class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"
                            focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15">
                            <path fill="currentColor"
                              d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z">
                            </path>
                            <polygon fill="currentColor"
                              points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9">
                            </polygon>
                          </svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a>
                    </li>
                    <li class="dropdown-item"><a href="https://blog.autojs.org/" rel="noopener noreferrer"
                        target="_blank" aria-label="官方博客" class="nav-link"><!---->官方博客<span><svg
                            class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"
                            focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15">
                            <path fill="currentColor"
                              d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z">
                            </path>
                            <polygon fill="currentColor"
                              points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9">
                            </polygon>
                          </svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a>
                    </li>
                    <li class="dropdown-item"><a href="https://pd.qq.com/s/gosos5" rel="noopener noreferrer"
                        target="_blank" aria-label="官方频道" class="nav-link"><!---->官方频道<span><svg
                            class="external-link-icon" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"
                            focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15">
                            <path fill="currentColor"
                              d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z">
                            </path>
                            <polygon fill="currentColor"
                              points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9">
                            </polygon>
                          </svg><span class="external-link-icon-sr-only">open in new window</span></span><!----></a>
                    </li>
                  </ul>
                </button></div>
            </div>
          </nav><!---->
        </div>
        <div class="navbar-right"><!---->
          <div class="nav-item">
            <div class="dropdown-wrapper i18n-dropdown"><button class="dropdown-title" type="button"
                aria-label="选择语言"><!--[--><svg xmlns="http://www.w3.org/2000/svg" class="icon i18n-icon"
                  viewBox="0 0 1024 1024" fill="currentColor" aria-label="i18n icon"
                  style="width:1rem;height:1rem;vertical-align:middle;">
                  <path
                    d="M379.392 460.8 494.08 575.488l-42.496 102.4L307.2 532.48 138.24 701.44l-71.68-72.704L234.496 460.8l-45.056-45.056c-27.136-27.136-51.2-66.56-66.56-108.544h112.64c7.68 14.336 16.896 27.136 26.112 35.84l45.568 46.08 45.056-45.056C382.976 312.32 409.6 247.808 409.6 204.8H0V102.4h256V0h102.4v102.4h256v102.4H512c0 70.144-37.888 161.28-87.04 210.944L378.88 460.8zM576 870.4 512 1024H409.6l256-614.4H768l256 614.4H921.6l-64-153.6H576zM618.496 768h196.608L716.8 532.48 618.496 768z">
                  </path>
                </svg><!--]--><span class="arrow"></span>
                <ul class="nav-dropdown">
                  <li class="dropdown-item"><a href="../../en/en.html" class="nav-link"
                      aria-label="English"><!---->English<!----></a></li>
                  <li class="dropdown-item"><a aria-current="page" href="files.html"
                      class="router-link-active router-link-exact-active nav-link active"
                      aria-label="简体中文"><!---->简体中文<!----></a></li>
                </ul>
              </button></div>
          </div><!---->
          <div class="nav-item hide-in-mobile"><button id="appearance-switch"><svg xmlns="http://www.w3.org/2000/svg"
                class="icon auto-icon" viewBox="0 0 1024 1024" fill="currentColor" aria-label="auto icon"
                style="display:block;">
                <path
                  d="M512 992C246.92 992 32 777.08 32 512S246.92 32 512 32s480 214.92 480 480-214.92 480-480 480zm0-840c-198.78 0-360 161.22-360 360 0 198.84 161.22 360 360 360s360-161.16 360-360c0-198.78-161.22-360-360-360zm0 660V212c165.72 0 300 134.34 300 300 0 165.72-134.28 300-300 300z">
                </path>
              </svg><svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" viewBox="0 0 1024 1024"
                fill="currentColor" aria-label="dark icon" style="display:none;">
                <path
                  d="M524.8 938.667h-4.267a439.893 439.893 0 0 1-313.173-134.4 446.293 446.293 0 0 1-11.093-597.334A432.213 432.213 0 0 1 366.933 90.027a42.667 42.667 0 0 1 45.227 9.386 42.667 42.667 0 0 1 10.24 42.667 358.4 358.4 0 0 0 82.773 375.893 361.387 361.387 0 0 0 376.747 82.774 42.667 42.667 0 0 1 54.187 55.04 433.493 433.493 0 0 1-99.84 154.88 438.613 438.613 0 0 1-311.467 128z">
                </path>
              </svg><svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" viewBox="0 0 1024 1024"
                fill="currentColor" aria-label="light icon" style="display:none;">
                <path
                  d="M952 552h-80a40 40 0 0 1 0-80h80a40 40 0 0 1 0 80zM801.88 280.08a41 41 0 0 1-57.96-57.96l57.96-58a41.04 41.04 0 0 1 58 58l-58 57.96zM512 752a240 240 0 1 1 0-480 240 240 0 0 1 0 480zm0-560a40 40 0 0 1-40-40V72a40 40 0 0 1 80 0v80a40 40 0 0 1-40 40zm-289.88 88.08-58-57.96a41.04 41.04 0 0 1 58-58l57.96 58a41 41 0 0 1-57.96 57.96zM192 512a40 40 0 0 1-40 40H72a40 40 0 0 1 0-80h80a40 40 0 0 1 40 40zm30.12 231.92a41 41 0 0 1 57.96 57.96l-57.96 58a41.04 41.04 0 0 1-58-58l58-57.96zM512 832a40 40 0 0 1 40 40v80a40 40 0 0 1-80 0v-80a40 40 0 0 1 40-40zm289.88-88.08 58 57.96a41.04 41.04 0 0 1-58 58l-57.96-58a41 41 0 0 1 57.96-57.96z">
                </path>
              </svg></button></div>
          <div class="search-box" role="search" data-v-f3875574><input value="" aria-label="Search" class=""
              placeholder="Search" autocomplete="off" spellcheck="false" data-v-f3875574><!----></div><!----><button
            class="toggle-navbar-button" aria-label="Toggle Navbar" aria-expanded="false"
            aria-controls="nav-screen"><span class="button-container"><span class="button-top"></span><span
                class="button-middle"></span><span class="button-bottom"></span></span></button>
        </div>
      </header><!----><!--]--><!---->
      <div class="toggle-sidebar-wrapper"><span class="arrow left"></span></div>
      <aside class="sidebar"><!--[--><!----><!--]-->
        <ul class="sidebar-links">
          <li>
            <section class="sidebar-group">
              <p class="sidebar-heading"><!----><span class="title">指南</span><!----></p>
              <ul class="sidebar-links">
                <li><!--[--><a href="v8.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="阅读须知"><!---->阅读须知<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
              </ul>
            </section>
          </li>
          <li>
            <section class="sidebar-group">
              <p class="sidebar-heading"><!----><span class="title">API文档</span><!----></p>
              <ul class="sidebar-links">
                <li>
                  <section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span
                        class="title">自动化 -
                        控件操作</span><span class="arrow down"></span></button>
                    <ul class="sidebar-links">
                      <li><!--[--><a href="./automator/"
                          class="router-link-active router-link-exact-active nav-link sidebar-link sidebar-page"
                          aria-label="入门介绍" aria-current="page"><!---->入门介绍<!----></a>
                        <ul class="sidebar-sub-headers"></ul><!--]-->
                      </li>
                      <li><!--[--><a href="./automator/selector.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="选择器"><!---->选择器<!----></a>
                        <ul class="sidebar-sub-headers"></ul><!--]-->
                      </li>
                      <li><!--[--><a href="./automator/uiobject.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="控件和控件集合"><!---->控件和控件集合<!----></a>
                        <ul class="sidebar-sub-headers"></ul><!--]-->
                      </li>
                      <li><!--[--><a href="./automator/api.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="automator与其他函数"><!---->automator与其他函数<!----></a>
                        <ul class="sidebar-sub-headers"></ul><!--]-->
                      </li>
                    </ul>
                  </section>
                </li>
                <li><!--[--><a href="./coordinatesBasedAutomation.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="自动化 - 坐标操作"><!---->自动化 -
                    坐标操作<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./app.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="app - 应用"><!---->app -
                    应用<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./base64.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="base64"><!---->base64<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./colors.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="colors - 颜色"><!---->colors - 颜色<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./canvas.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="canvas - 画布"><!---->canvas - 画布<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./console.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="console - 控制台"><!---->console - 控制台<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./crypto.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="crypto - 加解密与消息摘要"><!---->crypto - 加解密与消息摘要<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./debug.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="debug - 调试工具"><!---->debug - 调试工具<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./device.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="device - 设备"><!---->device - 设备<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./dialogs.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="dialogs - 对话框"><!---->dialogs - 对话框<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./engines.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="engines - 脚本引擎"><!---->engines - 脚本引擎<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./events.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="events - 事件与监听"><!---->events - 事件与监听<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./floaty.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="floaty - 悬浮窗"><!---->floaty - 悬浮窗<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./files.html" class="nav-link sidebar-link sidebar-page active"
                    aria-label="files - 文件系统"><!---->files - 文件系统<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./globals.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="globals - 全局变量与函数"><!---->globals - 全局变量与函数<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./http.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="http - HTTP网络请求"><!---->http - HTTP网络请求<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./images.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="images - 图片处理"><!---->images - 图片处理<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./keys.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="keys - 按键模拟"><!---->keys
                    - 按键模拟<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./media.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="media - 多媒体"><!---->media
                    - 多媒体<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./modules.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="module - 模块"><!---->module - 模块<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./ocr.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="ocr - 文字识别"><!---->ocr -
                    文字识别<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./plugins.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="plugins - 插件"><!---->plugins - 插件<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./powerManager.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="power_manager - 电源管理"><!---->power_manager - 电源管理<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./sensors.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="sensors - 传感器"><!---->sensors - 传感器<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./shell.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="shell - Shell命令"><!---->shell - Shell命令<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./storages.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="storages - 本地存储"><!---->storages - 本地存储<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./settings.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="settings - 设置"><!---->settings - 设置<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./threads.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="threads - 多线程"><!---->threads - 多线程<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./timers.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="timers - 定时器"><!---->timers - 定时器<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./timedTasks.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="work_manager - 定时与任务"><!---->work_manager - 定时与任务<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li>
                  <section class="sidebar-group"><button class="sidebar-heading clickable"><!----><span
                        class="title">ui - 用户界面</span><span class="arrow down"></span></button>
                    <ul class="sidebar-links">
                      <li><a href="/docs/zh/v8/ui/ui.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="ui入门介绍"><!---->ui入门介绍<!----></a>
                        <ul class="sidebar-sub-headers"></ul>
                      </li>
                      <li><a href="/docs/zh/v8/ui/basic.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="基础布局与控件"><!---->基础布局与控件<!----></a>
                        <ul class="sidebar-sub-headers"></ul>
                      </li>
                      <li><a href="/docs/zh/v8/ui/advanced.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="其他布局与控件"><!---->其他布局与控件<!----></a>
                        <ul class="sidebar-sub-headers"></ul>
                      </li>
                      <li><a href="/docs/zh/v8/ui/api.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="api文档"><!---->api文档<!----></a>
                        <ul class="sidebar-sub-headers"></ul>
                      </li>
                      <li><a href="/docs/zh/v8/ui/customWidget.html" class="nav-link sidebar-link sidebar-page"
                          aria-label="自定义控件"><!---->自定义控件<!----></a>
                        <ul class="sidebar-sub-headers"></ul>
                      </li>
                      <li><a aria-current="page" href="/docs/zh/v8/ui/webview.html"
                          class="router-link-active router-link-exact-active nav-link sidebar-link sidebar-page"
                          aria-label="使用Web编写界面"><!---->使用Web编写界面<!----></a>
                        <ul class="sidebar-sub-headers"></ul>
                      </li>
                    </ul>
                  </section>
                </li>
                <li><!--[--><a href="./util.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="util - 工具"><!---->util -
                    工具<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./webSocket.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="WebSocket"><!---->WebSocket<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
                <li><!--[--><a href="./zip.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="zip - 压缩与解压"><!---->zip -
                    压缩与解压<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
              </ul>
            </section>
          </li>
          <li>
            <section class="sidebar-group">
              <p class="sidebar-heading"><!----><span class="title">进阶</span><!----></p>
              <ul class="sidebar-links">
                <li><!--[--><a href="scriptingJava.html" class="nav-link sidebar-link sidebar-page"
                    aria-label="和Java交互"><!---->和Java交互<!----></a>
                  <ul class="sidebar-sub-headers"></ul><!--]-->
                </li>
              </ul>
            </section>
          </li>
        </ul><!--[--><!----><!--]-->
      </aside><!--[-->
      <main class="page" id="main-content"><!--[--><!---->
        <nav class="breadcrumb disable"></nav>
        <div class="page-title">
          <h1><!---->files - 文件系统</h1>
          <div class="page-info"><span class="date-info" aria-label="写作日期📅" data-balloon-pos="down"><svg
                xmlns="http://www.w3.org/2000/svg" class="icon calendar-icon" viewBox="0 0 1024 1024"
                fill="currentColor" aria-label="calendar icon">
                <path
                  d="M716.4 110.137c0-18.753-14.72-33.473-33.472-33.473-18.753 0-33.473 14.72-33.473 33.473v33.473h66.993v-33.473zm-334.87 0c0-18.753-14.72-33.473-33.473-33.473s-33.52 14.72-33.52 33.473v33.473h66.993v-33.473zm468.81 33.52H716.4v100.465c0 18.753-14.72 33.473-33.472 33.473a33.145 33.145 0 01-33.473-33.473V143.657H381.53v100.465c0 18.753-14.72 33.473-33.473 33.473a33.145 33.145 0 01-33.473-33.473V143.657H180.6A134.314 134.314 0 0046.66 277.595v535.756A134.314 134.314 0 00180.6 947.289h669.74a134.36 134.36 0 00133.94-133.938V277.595a134.314 134.314 0 00-133.94-133.938zm33.473 267.877H147.126a33.145 33.145 0 01-33.473-33.473c0-18.752 14.72-33.473 33.473-33.473h736.687c18.752 0 33.472 14.72 33.472 33.473a33.145 33.145 0 01-33.472 33.473z">
                </path>
              </svg><span>2022年10月22日</span>
              <meta property="datePublished" content="2022-10-22T07:36:15.000Z">
            </span></div>
          <hr>
        </div>
        <div class="toc-place-holder">
          <aside id="toc">
            <div class="toc-header">此页内容</div>
            <div class="toc-wrapper">
              <ul class="toc-list"><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-isfile-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.isFile(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-isdir-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.isDir(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-isemptydir-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.isEmptyDir(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-join-parent-child"
                    class="router-link-active router-link-exact-active toc-link level2">files.join(parent, child)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-create-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.create(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-createwithdirs-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.createWithDirs(path)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-exists-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.exists(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-ensuredir-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.ensureDir(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-read-path-encoding-utf-8"
                    class="router-link-active router-link-exact-active toc-link level2">files.read(path[, encoding =
                    &quot;utf-8&quot;])</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-readbytes-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.readBytes(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-write-path-text-encoding-utf-8"
                    class="router-link-active router-link-exact-active toc-link level2">files.write(path, text[,
                    encoding = &quot;utf-8&quot;])</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-writebytes-path-bytes"
                    class="router-link-active router-link-exact-active toc-link level2">files.writeBytes(path,
                    bytes)</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-append-path-text-encoding-utf-8"
                    class="router-link-active router-link-exact-active toc-link level2">files.append(path, text[,
                    encoding = &#39;utf-8&#39;])</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-appendbytes-path-text-encoding-utf-8"
                    class="router-link-active router-link-exact-active toc-link level2">files.appendBytes(path, text[,
                    encoding = &#39;utf-8&#39;])</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-copy-frompath-topath"
                    class="router-link-active router-link-exact-active toc-link level2">files.copy(fromPath, toPath)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-move-frompath-topath"
                    class="router-link-active router-link-exact-active toc-link level2">files.move(fromPath, toPath)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-rename-path-newname"
                    class="router-link-active router-link-exact-active toc-link level2">files.rename(path, newName)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-renamewithoutextension-path-newname"
                    class="router-link-active router-link-exact-active toc-link level2">files.renameWithoutExtension(path,
                    newName)</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-getname-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.getName(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-getnamewithoutextension-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.getNameWithoutExtension(path)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-getextension-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.getExtension(path)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-remove-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.remove(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-removedir-path"
                    class="router-link-active router-link-exact-active toc-link level2">files.removeDir(path)</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-getsdcardpath"
                    class="router-link-active router-link-exact-active toc-link level2">files.getSdcardPath()</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-cwd"
                    class="router-link-active router-link-exact-active toc-link level2">files.cwd()</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-path-relativepath"
                    class="router-link-active router-link-exact-active toc-link level2">files.path(relativePath)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#files-listdir-path-filter"
                    class="router-link-active router-link-exact-active toc-link level2">files.listDir(path[,
                    filter])</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#open-path-mode-r-encoding-utf-8-buffersize-8192"
                    class="router-link-active router-link-exact-active toc-link level2">open(path[, mode =
                    &quot;r&quot;, encoding = &quot;utf-8&quot;, bufferSize = 8192])</a></li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#readabletextfile-read"
                    class="router-link-active router-link-exact-active toc-link level2">ReadableTextFile.read()</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#readabletextfile-read-maxcount"
                    class="router-link-active router-link-exact-active toc-link level2">ReadableTextFile.read(maxCount)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#readabletextfile-readline"
                    class="router-link-active router-link-exact-active toc-link level2">ReadableTextFile.readline()</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#readabletextfile-readlines"
                    class="router-link-active router-link-exact-active toc-link level2">ReadableTextFile.readlines()</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page" href="https://pro.autojs.org/docs/zh/v8/files.html#close"
                    class="router-link-active router-link-exact-active toc-link level2">close()</a></li>
                <!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#pwritabletextfile-write-text"
                    class="router-link-active router-link-exact-active toc-link level2">PWritableTextFile.write(text)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#pwritabletextfile-writeline-line"
                    class="router-link-active router-link-exact-active toc-link level2">PWritableTextFile.writeline(line)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#pwritabletextfile-writelines-lines"
                    class="router-link-active router-link-exact-active toc-link level2">PWritableTextFile.writelines(lines)</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#pwritabletextfile-flush"
                    class="router-link-active router-link-exact-active toc-link level2">PWritableTextFile.flush()</a>
                </li><!----><!--]--><!--[-->
                <li class="toc-item"><a aria-current="page"
                    href="https://pro.autojs.org/docs/zh/v8/files.html#pwritabletextfile-close"
                    class="router-link-active router-link-exact-active toc-link level2">PWritableTextFile.close()</a>
                </li><!----><!--]-->
              </ul>
            </div>
          </aside>
        </div><!---->
        <div class="theme-hope-content">
          <h1 id="files-文件系统" tabindex="-1"><a class="header-anchor" href="#files-文件系统" aria-hidden="true">#</a> files -
            文件系统</h1>
          <blockquote>
            <p>Stability: 2 - Stable</p>
          </blockquote>
          <p>files模块提供了一些常见的文件处理，包括文件读写、移动、复制、删掉等。</p>
          <p>
            一次性的文件读写可以直接使用<code>files<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code>,
            <code>files<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code>,
            <code>files<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code>等方便的函数，但如果需要频繁读写或随机读写，则使用<code><span class="token function">open</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code>函数打开一个文件对象来操作文件，并在操作完毕后调用<code><span class="token function">close</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code>函数关闭文件。
          </p>
          <h2 id="files-isfile-path" tabindex="-1"><a class="header-anchor" href="#files-isfile-path"
              aria-hidden="true">#</a> files.isFile(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>返回路径path是否是文件。</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token function">log</span><span class="token punctuation">(</span>files<span class="token punctuation">.</span><span class="token function">isDir</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/文件夹/&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//返回false</span>
<span class="token function">log</span><span class="token punctuation">(</span>files<span class="token punctuation">.</span><span class="token function">isDir</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/文件.txt&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//返回true</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-isdir-path" tabindex="-1"><a class="header-anchor" href="#files-isdir-path"
              aria-hidden="true">#</a> files.isDir(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>返回路径path是否是文件夹。</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token function">log</span><span class="token punctuation">(</span>files<span class="token punctuation">.</span><span class="token function">isDir</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/文件夹/&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//返回true</span>
<span class="token function">log</span><span class="token punctuation">(</span>files<span class="token punctuation">.</span><span class="token function">isDir</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/文件.txt&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//返回false</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-isemptydir-path" tabindex="-1"><a class="header-anchor" href="#files-isemptydir-path"
              aria-hidden="true">#</a> files.isEmptyDir(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>返回文件夹path是否为空文件夹。如果该路径并非文件夹，则直接返回<code><span class="token boolean">false</span></code>。</p>
          <h2 id="files-join-parent-child" tabindex="-1"><a class="header-anchor" href="#files-join-parent-child"
              aria-hidden="true">#</a> files.join(parent, child)</h2>
          <ul>
            <li><code><span class="token property">parent</span></code> {string} 父目录路径</li>
            <li><code><span class="token property">child</span></code> {string} 子路径</li>
            <li>返回 {string}</li>
          </ul>
          <p>
            连接两个路径并返回，例如<code>files<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;1.txt&quot;</span><span class="token punctuation">)</span></code>返回&quot;/sdcard/1.txt&quot;。
          </p>
          <h2 id="files-create-path" tabindex="-1"><a class="header-anchor" href="#files-create-path"
              aria-hidden="true">#</a> files.create(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>创建一个文件或文件夹并返回是否创建成功。如果文件已经存在，则直接返回<code><span class="token boolean">false</span></code>。</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code>files<span class="token punctuation">.</span><span class="token function">create</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/新文件夹/&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-createwithdirs-path" tabindex="-1"><a class="header-anchor" href="#files-createwithdirs-path"
              aria-hidden="true">#</a> files.createWithDirs(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>
            创建一个文件或文件夹并返回是否创建成功。如果文件所在文件夹不存在，则先创建他所在的一系列文件夹。如果文件已经存在，则直接返回<code><span class="token boolean">false</span></code>。
          </p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code>files<span class="token punctuation">.</span><span class="token function">createWithDirs</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/新文件夹/新文件夹/新文件夹/1.txt&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-exists-path" tabindex="-1"><a class="header-anchor" href="#files-exists-path"
              aria-hidden="true">#</a> files.exists(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>返回在路径path处的文件是否存在。</p>
          <h2 id="files-ensuredir-path" tabindex="-1"><a class="header-anchor" href="#files-ensuredir-path"
              aria-hidden="true">#</a> files.ensureDir(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
          </ul>
          <p>确保路径path所在的文件夹存在。如果该路径所在文件夹不存在，则创建该文件夹。</p>
          <p>例如对于路径&quot;/sdcard/Download/ABC/1.txt&quot;，如果/Download/文件夹不存在，则会先创建Download，再创建ABC文件夹。</p>
          <h2 id="files-read-path-encoding-utf-8" tabindex="-1"><a class="header-anchor"
              href="#files-read-path-encoding-utf-8" aria-hidden="true">#</a> files.read(path[, encoding =
            &quot;utf-8&quot;])</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li><code><span class="token property">encoding</span></code> {string} 字符编码，可选，默认为utf-8</li>
            <li>返回 {string}</li>
          </ul>
          <p>读取文本文件path的所有内容并返回。如果文件不存在，则抛出<code><span class="token property">FileNotFoundException</span></code>。</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token function">log</span><span class="token punctuation">(</span>files<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-readbytes-path" tabindex="-1"><a class="header-anchor" href="#files-readbytes-path"
              aria-hidden="true">#</a> files.readBytes(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {byte[]}</li>
          </ul>
          <p>读取文件path的所有内容并返回一个字节数组。如果文件不存在，则抛出<code><span class="token property">FileNotFoundException</span></code>。
          </p>
          <p>注意，该数组是Java的数组，不具有JavaScript数组的forEach, slice等函数。</p>
          <p>一个以16进制形式打印文件的例子如下:</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token keyword">var</span> data <span class="token operator">=</span> files<span class="token punctuation">.</span><span class="token function">readBytes</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.png&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> sb <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>StringBuilder</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">var</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> data<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    sb<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>data<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token function">log</span><span class="token punctuation">(</span>sb<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-write-path-text-encoding-utf-8" tabindex="-1"><a class="header-anchor"
              href="#files-write-path-text-encoding-utf-8" aria-hidden="true">#</a> files.write(path, text[, encoding =
            &quot;utf-8&quot;])</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li><code><span class="token property">text</span></code> {string} 要写入的文本内容</li>
            <li><code><span class="token property">encoding</span></code> {string} 字符编码</li>
          </ul>
          <p>把text写入到文件path中。如果文件存在则覆盖，不存在则创建。</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token keyword">var</span> text <span class="token operator">=</span> <span class="token string">&quot;文件内容&quot;</span><span class="token punctuation">;</span>
<span class="token comment">//写入文件</span>
files<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">,</span> text<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//用其他应用查看文件</span>
app<span class="token punctuation">.</span><span class="token function">viewFile</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-writebytes-path-bytes" tabindex="-1"><a class="header-anchor"
              href="#files-writebytes-path-bytes" aria-hidden="true">#</a> files.writeBytes(path, bytes)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li><code><span class="token property">bytes</span></code> {byte[]} 字节数组，要写入的二进制数据</li>
          </ul>
          <p>把bytes写入到文件path中。如果文件存在则覆盖，不存在则创建。</p>
          <h2 id="files-append-path-text-encoding-utf-8" tabindex="-1"><a class="header-anchor"
              href="#files-append-path-text-encoding-utf-8" aria-hidden="true">#</a> files.append(path, text[, encoding
            = &#39;utf-8&#39;])</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li><code><span class="token property">text</span></code> {string} 要写入的文本内容</li>
            <li><code><span class="token property">encoding</span></code> {string} 字符编码</li>
          </ul>
          <p>把text追加到文件path的末尾。如果文件不存在则创建。</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token keyword">var</span> text <span class="token operator">=</span> <span class="token string">&quot;追加的文件内容&quot;</span><span class="token punctuation">;</span>
files<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">,</span> text<span class="token punctuation">)</span><span class="token punctuation">;</span>
files<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">,</span> text<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">//用其他应用查看文件</span>
app<span class="token punctuation">.</span><span class="token function">viewFile</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="files-appendbytes-path-text-encoding-utf-8" tabindex="-1"><a class="header-anchor"
              href="#files-appendbytes-path-text-encoding-utf-8" aria-hidden="true">#</a> files.appendBytes(path, text[,
            encoding = &#39;utf-8&#39;])</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li><code><span class="token property">bytes</span></code> {byte[]} 字节数组，要写入的二进制数据</li>
          </ul>
          <p>把bytes追加到文件path的末尾。如果文件不存在则创建。</p>
          <h2 id="files-copy-frompath-topath" tabindex="-1"><a class="header-anchor" href="#files-copy-frompath-topath"
              aria-hidden="true">#</a> files.copy(fromPath, toPath)</h2>
          <ul>
            <li><code><span class="token property">fromPath</span></code> {string} 要复制的原文件路径</li>
            <li><code><span class="token property">toPath</span></code> {string} 复制到的文件路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>
            复制文件，返回是否复制成功。例如<code>files<span class="token punctuation">.</span><span class="token function">copy</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/sdcard/Download/1.txt&quot;</span><span class="token punctuation">)</span></code>。
          </p>
          <h2 id="files-move-frompath-topath" tabindex="-1"><a class="header-anchor" href="#files-move-frompath-topath"
              aria-hidden="true">#</a> files.move(fromPath, toPath)</h2>
          <ul>
            <li><code><span class="token property">fromPath</span></code> {string} 要移动的原文件路径</li>
            <li><code><span class="token property">toPath</span></code> {string} 移动到的文件路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>
            移动文件，返回是否移动成功。例如<code>files<span class="token punctuation">.</span><span class="token function">move</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;/sdcard/Download/1.txt&quot;</span><span class="token punctuation">)</span></code>会把1.txt文件从sd卡根目录移动到Download文件夹。
          </p>
          <h2 id="files-rename-path-newname" tabindex="-1"><a class="header-anchor" href="#files-rename-path-newname"
              aria-hidden="true">#</a> files.rename(path, newName)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 要重命名的原文件路径</li>
            <li><code><span class="token property">newName</span></code> {string} 要重命名的新文件名</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>
            重命名文件，并返回是否重命名成功。例如<code>files<span class="token punctuation">.</span><span class="token function">rename</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;2.txt&quot;</span><span class="token punctuation">)</span></code>。
          </p>
          <h2 id="files-renamewithoutextension-path-newname" tabindex="-1"><a class="header-anchor"
              href="#files-renamewithoutextension-path-newname" aria-hidden="true">#</a>
            files.renameWithoutExtension(path, newName)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 要重命名的原文件路径</li>
            <li><code><span class="token property">newName</span></code> {string} 要重命名的新文件名</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>
            重命名文件，不包含拓展名，并返回是否重命名成功。例如<code>files<span class="token punctuation">.</span><span class="token function">rename</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;2&quot;</span><span class="token punctuation">)</span></code>会把&quot;1.txt&quot;重命名为&quot;2.txt&quot;。
          </p>
          <h2 id="files-getname-path" tabindex="-1"><a class="header-anchor" href="#files-getname-path"
              aria-hidden="true">#</a> files.getName(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {string}</li>
          </ul>
          <p>
            返回文件的文件名。例如<code>files<span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">)</span></code>返回&quot;1.txt&quot;。
          </p>
          <h2 id="files-getnamewithoutextension-path" tabindex="-1"><a class="header-anchor"
              href="#files-getnamewithoutextension-path" aria-hidden="true">#</a> files.getNameWithoutExtension(path)
          </h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {string}</li>
          </ul>
          <p>
            返回不含拓展名的文件的文件名。例如<code>files<span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">)</span></code>返回&quot;1&quot;。
          </p>
          <h2 id="files-getextension-path" tabindex="-1"><a class="header-anchor" href="#files-getextension-path"
              aria-hidden="true">#</a> files.getExtension(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {string}</li>
          </ul>
          <p>
            返回文件的拓展名。例如<code>files<span class="token punctuation">.</span><span class="token function">getExtension</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/1.txt&quot;</span><span class="token punctuation">)</span></code>返回&quot;txt&quot;。
          </p>
          <h2 id="files-remove-path" tabindex="-1"><a class="header-anchor" href="#files-remove-path"
              aria-hidden="true">#</a> files.remove(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>删除文件或<strong>空文件夹</strong>，返回是否删除成功。</p>
          <h2 id="files-removedir-path" tabindex="-1"><a class="header-anchor" href="#files-removedir-path"
              aria-hidden="true">#</a> files.removeDir(path)</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li>返回 {boolean}</li>
          </ul>
          <p>删除文件夹，如果文件夹不为空，则删除该文件夹的所有内容再删除该文件夹，返回是否全部删除成功。</p>
          <h2 id="files-getsdcardpath" tabindex="-1"><a class="header-anchor" href="#files-getsdcardpath"
              aria-hidden="true">#</a> files.getSdcardPath()</h2>
          <ul>
            <li>返回 {string}</li>
          </ul>
          <p>返回SD卡路径。所谓SD卡，即外部存储器。</p>
          <h2 id="files-cwd" tabindex="-1"><a class="header-anchor" href="#files-cwd" aria-hidden="true">#</a>
            files.cwd()</h2>
          <ul>
            <li>返回 {string}</li>
          </ul>
          <p>
            返回脚本的&quot;当前工作文件夹路径&quot;。该路径指的是，如果脚本本身为脚本文件，则返回这个脚本文件所在目录；否则返回<code><span class="token keyword">null</span></code>获取其他设定路径。
          </p>
          <p>
            例如，对于脚本文件&quot;/sdcard/脚本/1.js&quot;运行<code>files<span class="token punctuation">.</span><span class="token function">cwd</span><span class="token punctuation">(</span><span class="token punctuation">)</span></code>返回&quot;/sdcard/脚本/&quot;。
          </p>
          <h2 id="files-path-relativepath" tabindex="-1"><a class="header-anchor" href="#files-path-relativepath"
              aria-hidden="true">#</a> files.path(relativePath)</h2>
          <ul>
            <li><code><span class="token property">relativePath</span></code> {string} 相对路径</li>
            <li>返回 {string}</li>
          </ul>
          <p>
            返回相对路径对应的绝对路径。例如<code>files<span class="token punctuation">.</span><span class="token function">path</span><span class="token punctuation">(</span><span class="token string">&quot;./1.png&quot;</span><span class="token punctuation">)</span></code>，如果运行这个语句的脚本位于文件夹&quot;/sdcard/脚本/&quot;中，则返回<code><span class="token string">&quot;/sdcard/脚本/1.png&quot;</span></code>。
          </p>
          <h2 id="files-listdir-path-filter" tabindex="-1"><a class="header-anchor" href="#files-listdir-path-filter"
              aria-hidden="true">#</a> files.listDir(path[, filter])</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 路径</li>
            <li><code><span class="token property">filter</span></code> {Function}
              过滤函数，可选。接收一个<code><span class="token property">string</span></code>参数（文件名），返回一个<code><span class="token property">boolean</span></code>值。
            </li>
          </ul>
          <p>列出文件夹path下的满足条件的文件和文件夹的名称的数组。如果不加filter参数，则返回所有文件和文件夹。</p>
          <p>列出sdcard目录下所有文件和文件夹为:</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token keyword">var</span> arr <span class="token operator">=</span> files<span class="token punctuation">.</span><span class="token function">listDir</span><span class="token punctuation">(</span><span class="token string">&quot;/sdcard/&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">log</span><span class="token punctuation">(</span>arr<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
              <div class="line-number"></div>
            </div>
          </div>
          <p>列出脚本目录下所有js脚本文件为:</p>
          <div class="language-javascript ext-js line-numbers-mode">
            <pre class="language-javascript"><code><span class="token keyword">var</span> dir <span class="token operator">=</span> <span class="token string">&quot;/sdcard/脚本/&quot;</span><span class="token punctuation">;</span>
<span class="token keyword">var</span> jsFiles <span class="token operator">=</span> files<span class="token punctuation">.</span><span class="token function">listDir</span><span class="token punctuation">(</span>dir<span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">name</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> name<span class="token punctuation">.</span><span class="token function">endsWith</span><span class="token punctuation">(</span><span class="token string">&quot;.js&quot;</span><span class="token punctuation">)</span> <span class="token operator">&amp;&amp;</span> files<span class="token punctuation">.</span><span class="token function">isFile</span><span class="token punctuation">(</span>files<span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span>dir<span class="token punctuation">,</span> name<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token function">log</span><span class="token punctuation">(</span>jsFiles<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
            <div class="line-numbers" aria-hidden="true">
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
              <div class="line-number"></div>
            </div>
          </div>
          <h2 id="open-path-mode-r-encoding-utf-8-buffersize-8192" tabindex="-1"><a class="header-anchor"
              href="#open-path-mode-r-encoding-utf-8-buffersize-8192" aria-hidden="true">#</a> open(path[, mode =
            &quot;r&quot;, encoding = &quot;utf-8&quot;, bufferSize = 8192])</h2>
          <ul>
            <li><code><span class="token property">path</span></code> {string} 文件路径，例如&quot;/sdcard/1.txt&quot;。</li>
            <li><code><span class="token property">mode</span></code> {string} 文件打开模式，包括: <ul>
                <li>&quot;r&quot;: 只读文本模式。该模式下只能对文件执行<strong>文本</strong>读取操作。</li>
                <li>&quot;w&quot;: 只写文本模式。该模式下只能对文件执行<strong>文本</strong>覆盖写入操作。</li>
                <li>&quot;a&quot;: 附加文本模式。该模式下将会把写入的文本附加到文件末尾。</li>
                <li>&quot;rw&quot;: 随机读写文本模式。该模式下将会把写入的文本附加到文件末尾。<br> 目前暂不支持二进制模式，随机读写模式。</li>
              </ul>
            </li>
            <li><code><span class="token property">encoding</span></code> {string} 字符编码。</li>
            <li><code><span class="token property">bufferSize</span></code> {number} 文件读写的缓冲区大小。</li>
          </ul>
          <p>打开一个文件。根据打开模式返回不同的文件对象。包括：</p>
          <ul>
            <li>&quot;r&quot;: 返回一个ReadableTextFile对象。</li>
            <li>&quot;w&quot;, &quot;a&quot;: 返回一个WritableTextFile对象。</li>
          </ul>
          <p>对于&quot;w&quot;模式，如果文件并不存在，则会创建一个，已存在则会清空该文件内容；其他模式文件不存在会抛出FileNotFoundException。</p>
          <h1 id="readabletextfile" tabindex="-1"><a class="header-anchor" href="#readabletextfile"
              aria-hidden="true">#</a> ReadableTextFile</h1>
          <p>可读文件对象。</p>
          <h2 id="readabletextfile-read" tabindex="-1"><a class="header-anchor" href="#readabletextfile-read"
              aria-hidden="true">#</a> ReadableTextFile.read()</h2>
          <p>返回该文件剩余的所有内容的字符串。</p>
          <h2 id="readabletextfile-read-maxcount" tabindex="-1"><a class="header-anchor"
              href="#readabletextfile-read-maxcount" aria-hidden="true">#</a> ReadableTextFile.read(maxCount)</h2>
          <ul>
            <li><code><span class="token property">maxCount</span></code> {Number} 最大读取的字符数量</li>
          </ul>
          <p>读取该文件接下来最长为maxCount的字符串并返回。即使文件剩余内容不足maxCount也不会出错。</p>
          <h2 id="readabletextfile-readline" tabindex="-1"><a class="header-anchor" href="#readabletextfile-readline"
              aria-hidden="true">#</a> ReadableTextFile.readline()</h2>
          <p>读取一行并返回（不包含换行符）。</p>
          <h2 id="readabletextfile-readlines" tabindex="-1"><a class="header-anchor" href="#readabletextfile-readlines"
              aria-hidden="true">#</a> ReadableTextFile.readlines()</h2>
          <p>读取剩余的所有行，并返回它们按顺序组成的字符串数组。</p>
          <h2 id="close" tabindex="-1"><a class="header-anchor" href="#close" aria-hidden="true">#</a> close()</h2>
          <p>关闭该文件。</p>
          <p><strong>打开一个文件不再使用时务必关闭</strong></p>
          <h1 id="pwritabletextfile" tabindex="-1"><a class="header-anchor" href="#pwritabletextfile"
              aria-hidden="true">#</a> PWritableTextFile</h1>
          <p>可写文件对象。</p>
          <h2 id="pwritabletextfile-write-text" tabindex="-1"><a class="header-anchor"
              href="#pwritabletextfile-write-text" aria-hidden="true">#</a> PWritableTextFile.write(text)</h2>
          <ul>
            <li><code><span class="token property">text</span></code> {string} 文本</li>
          </ul>
          <p>把文本内容text写入到文件中。</p>
          <h2 id="pwritabletextfile-writeline-line" tabindex="-1"><a class="header-anchor"
              href="#pwritabletextfile-writeline-line" aria-hidden="true">#</a> PWritableTextFile.writeline(line)</h2>
          <ul>
            <li><code><span class="token property">text</span></code> {string} 文本</li>
          </ul>
          <p>把文本line写入到文件中并写入一个换行符。</p>
          <h2 id="pwritabletextfile-writelines-lines" tabindex="-1"><a class="header-anchor"
              href="#pwritabletextfile-writelines-lines" aria-hidden="true">#</a> PWritableTextFile.writelines(lines)
          </h2>
          <ul>
            <li><code><span class="token property">lines</span></code> {Array} 字符串数组</li>
          </ul>
          <p>把很多行写入到文件中....</p>
          <h2 id="pwritabletextfile-flush" tabindex="-1"><a class="header-anchor" href="#pwritabletextfile-flush"
              aria-hidden="true">#</a> PWritableTextFile.flush()</h2>
          <p>把缓冲区内容输出到文件中。</p>
          <h2 id="pwritabletextfile-close" tabindex="-1"><a class="header-anchor" href="#pwritabletextfile-close"
              aria-hidden="true">#</a> PWritableTextFile.close()</h2>
          <p>关闭文件。同时会被缓冲区内容输出到文件。</p>
          <p><strong>打开一个文件写入后，不再使用时务必关闭，否则文件可能会丢失</strong></p>
        </div><!---->
        <footer class="page-meta"><!---->
          <div class="meta-item update-time"><span class="label">上次编辑于: </span><!----></div>
          <div class="meta-item contributors"><span class="label">贡献者: </span><!--[--><!--[--><span class="contributor"
              title="email: 946994919@qq.com">hyb1996</span><!--]--><!--]--></div>
        </footer>
        <nav class="page-nav"><a href="floaty.html" class="nav-link prev" aria-label="floaty - 悬浮窗">
            <div class="hint"><span class="arrow left"></span>上一页</div>
            <div class="link"><!---->floaty - 悬浮窗</div>
          </a><a href="globals.html" class="nav-link next" aria-label="globals - 全局变量与函数">
            <div class="hint">下一页<span class="arrow right"></span></div>
            <div class="link">globals - 全局变量与函数<!----></div>
          </a></nav><!----><!----><!--]-->
      </main><!--]--><!----><!--]-->
    </div><!--]--><!----><!----><!--]-->
  </div>
  <script type="module" src="../../assets/app.6aa2b576.js" defer></script>
</body>

</html>